app.controller('PassengerModalCtrl', function ($scope, $modalInstance, toaster, param) {

	$scope.submitting = false;
	$scope.param = param;
	if ($scope.param.data == null) {
		$scope.param.data = {};
	}

	if ($scope.param.type == "insert") {
		$scope.qr = true;
		$scope.param.data.points = 0;
	}

	$scope.ok = function () {
		$scope.submitting = true;
		if ($scope.param.type == "insert") {
			if ($scope.myForm.$valid) {
				if ($scope.password == undefined || $scope.password == "" || $scope.password.length < 6) {
					toaster.pop('warning', '错误', '密码长度必须大于等于6');
					$scope.submitting = false;
					return;
				} else if ($scope.newpassword == undefined || $scope.newpassword == "" || $scope.newpassword.length < 6) {
					toaster.pop('warning', '错误', '确认密码长度必须大于等于6');
					$scope.submitting = false;
					return;
				} else if ($scope.password != $scope.newpassword) {
					toaster.pop('warning', '错误', '两次密码输入不一致');
					$scope.submitting = false;
					return;
				} else {
					$scope.param.data.password = $scope.password;
					$modalInstance.close($scope.param);
				}
			}
		} else if ($scope.param.type == "update") {
			if ($scope.myForm.$valid) {
				if ($scope.password != undefined) {
					if ($scope.password.length >= 6) {
						$scope.param.data.password = $scope.password;
						$modalInstance.close($scope.param);
					} else if ($scope.password.length < 6 && $scope.password.length > 0) {
						toaster.pop('warning', '错误', '密码长度必须大于等于6');
						$scope.submitting = false;
						return;
					}
				}
				$modalInstance.close($scope.param);
			}
		}
		$scope.submitting = false;
	};

	$scope.cancel = function () {
		$modalInstance.dismiss('cancel');
		$scope.submitting = false;
	};
});